//
//  USOurListView.m
//  us
//
//  Created by karry on 2025/5/7.
//

#import "USOurListView.h"

@interface USOurListView()

@property (nonatomic,strong) CAShapeLayer *lineLayer;
@property (nonatomic,strong) UIView *c_v0;

@end

@implementation USOurListView


- (void)awakeFromNib{
    [super awakeFromNib];
    [self setupView];
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupView];
    }
    return self;
}

- (void)setupView{
    
    self.layer.cornerRadius = 14.f;
    
    UIView *c_v0 = [UIView new];
    _c_v0 = c_v0;
    c_v0.layer.cornerRadius = 12.f;
    c_v0.backgroundColor = [UIColor colorWithWhite:1 alpha:0.2];
    [self addSubview:c_v0];
    
    [c_v0 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_offset(6);
        make.right.mas_offset(-6);
        make.bottom.mas_offset(-35);
    }];
    
    self.lineLayer = [CAShapeLayer layer];
    self.lineLayer.strokeColor = [UIColor.whiteColor colorWithAlphaComponent:.5].CGColor;
    self.lineLayer.fillColor = UIColor.clearColor.CGColor;
    self.lineLayer.lineWidth = 2.f;
    self.lineLayer.lineCap = kCALineCapRound;
    self.lineLayer.lineDashPattern = @[@4,@6];
    [c_v0.layer addSublayer:self.lineLayer];
    
    UIView *toolBar = [UIView new];
    [self addSubview:toolBar];
    [toolBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_offset(0);
        make.top.mas_equalTo(c_v0.mas_bottom);
    }];
    
    self.progressLab = [UILabel new];
    self.progressLab.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
    self.progressLab.textColor = [[UIColor blackColor] colorWithAlphaComponent:.2];
    [toolBar addSubview:self.progressLab];

    [self.progressLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(12);
        make.centerY.mas_equalTo(toolBar);
    }];
    
    self.progressView = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
    self.progressView.progressTintColor = UIColor.whiteColor;
    self.progressView.trackTintColor = [[UIColor blackColor] colorWithAlphaComponent:.1];
    self.progressView.layer.cornerRadius = 3;
    self.progressView.layer.masksToBounds = YES;
    
    [toolBar addSubview:self.progressView];
    [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-12);
        make.height.mas_equalTo(6);
        make.centerY.mas_equalTo(self.progressLab);
        make.width.mas_equalTo(90);
        make.left.mas_equalTo(self.progressLab.mas_right).mas_offset(-6);
    }];
    
    self.titleLab = [UILabel new];
    self.titleLab.adjustsFontSizeToFitWidth = YES;
    self.titleLab.numberOfLines = 0;
    self.titleLab.font = [UIFont systemFontOfSize:20 weight:UIFontWeightSemibold];
    [c_v0 addSubview:self.titleLab];
    self.titleLab.textAlignment = NSTextAlignmentCenter;
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_offset(12);
        make.bottom.right.mas_offset(-12);
    }];
}

- (void)setColor:(UIColor *)color{
    _color = color;
    self.backgroundColor = color;
    self.titleLab.textColor = [color jk_darkenColor:0.35];
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGRect bounds = self.c_v0.bounds;
    bounds = CGRectInset(bounds, 6, 6);
    
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:bounds cornerRadius:12];
    self.lineLayer.path = path.CGPath;
    
}


@end
